package Classes.GameViews.ViewPanels
{
	import Classes.GameViews.ViewIcons.VI_VectorIcon;
	import Classes.GameViews.ViewScenes.VS_Main;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;

	/** 
	 * npc动画播放面板
	 * @author thy
	 * @version 1.0.0 
	 * 创建时间：Mar 27, 2012 7:31:10 PM 
	 */ 
	public class VP_NPCFlashPlayView extends ViewPanel
	{
		private static var _instance:VP_NPCFlashPlayView;
		private var callFun:Function;
		
//		private var _interfaceUI:Sprite;
		public function VP_NPCFlashPlayView()
		{
			super();
		}
		private var container:DisplayObject;
		private var mc:MovieClip;
		private var flag:Boolean=true;
		public function setFlashPlayInfo(dis:DisplayObject,callbackFun:Function):void
		{
			this.callFun=callbackFun;
			container=dis;
			this.flag=true;
//			var sp:Sprite=new Sprite();
//			sp.graphics.drawRect(0,0,ZombieTown.instance.stage.stageWidth,ZombieTown.instance.stage.stageHeight);
//			var dobj:DisplayObject=sp.addChild(dis);
//			dobj.x=ZombieTown.instance.stage.stageWidth/2;
//			dobj.y=ZombieTown.instance.stage.stageHeight/2;
			
			this.addChild(container);
			
			this.addEventListener(Event.ENTER_FRAME,enterFrame);
		}
		
		private function enterFrame(e:Event):void
		{
			if(null!=(container as VI_VectorIcon).getChildByName("pic")as MovieClip && flag)
			{
				this.mc=(container as VI_VectorIcon).getChildByName("pic")as MovieClip;
				this.openNpcFlashPlay();
				this.flag=false;
			}
			if(null!=this.mc && mc.currentFrame==mc.totalFrames)
			{
				this.removeEventListener(Event.ENTER_FRAME,enterFrame);
				this.mc=null;
				this.close();
				this.callFun();
			}
		}
		
		/**
		 * 打开NPC动画播放 
		 */		
		public function openNpcFlashPlay():void
		{
			this.openAt(VS_Main.instance,true);
			this.toCenter();
		}
		
		
		/**
		 *关闭界面 
		 */		
		public function closeWin():void
		{
			this.close();
		}
		
		
		public static function get instance():VP_NPCFlashPlayView
		{
			if(!_instance)_instance=new VP_NPCFlashPlayView();
			return _instance;
		}
		
//		public function get interfaceUI():Sprite
//		{
//			return _interfaceUI;
//		}
	}
}
